/*
 * 创建时间：9-24
 * 作者：彭济
 * 功能描述：文章类型表
 * 修改时间：
 */

import Sequelize from 'sequelize'
import sequelize from './../../database'

const ArticleType = sequelize.define('sys_articletype',{
	id:{
        type: Sequelize.UUIDV4,
        defaultValue: Sequelize.UUIDV4,
        unique: true,
        allowNull: false,
        primaryKey:true
    },
    type_name:{
    	type: Sequelize.STRING,
    	allowNull: false
    },
    remark:{
    	type:Sequelize.STRING,
    	allowNull:false
    }
},{
	tableName:'sys_articletype',
	freezeTableName:false,
	updatedAt:'updated_at',
    createdAt:'created_at',
});

class ArticletypeModel{
	insertType(record){
		return ArticleType.create(record);
	}
    findAllType(){
        return ArticleType.findAll();
    }
	delTypeById(id){
		return 	ArticleType.destroy({
			where:{
				id:id
			}
		});
	}
	findListPublish(){
        return ArticleType.findAll({
            where:{
                is_publist:1
            }
        })
    }
	findAllType(){
		return ArticleType.findAll();
	}
	findTypeById(id){
		return ArticleType.findById(id);
	}
	pagingType(record){
		return ArticleType.findAndCount({
            limit:record.page_size,
            offset: record.page_size * (record.page_no -1)
        })
	}
	updateType(record){
		return ArticleType.update(record,
            {
                'where':{
                    'id': record.id
                }
            }
        )
	}

}
module.exports = new ArticletypeModel();